{include file="User/error"}
<span class="glyphicon glyphicon-map-marker" aria-hidden="true">
    <span>系统</span> /
    <span>系统权限</span> /
    <span>用户管理</span> /
    <span>用户编辑</span>
</span>
<row>
    <div class="col-md-8 col-md-offset-2" style="margin-top: 37px;">
        <form class="form-horizontal" onsubmit="return getUserEdit('__HTTP__')">
            <input name="id" type="hidden" id="id" value="{$user.id}" />
            <div class="form-group">
                <label for="title" class="col-md-3 control-label">
                    <div class="text-center">用户昵称</div>
                </label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="nickname" value="{$user.nickname}"
                           name="nickname" placeholder="输入用户昵称">
                </div>
            </div>
            <div class="form-group">
                <label for="user_type" class="col-md-3 control-label">
                    <div class="text-center">用户类型</div>
                </label>
                <div class="col-md-9">
                    <select class="form-control" id="user_type" name="user_type">
                        <option value="0">请选择</option>
                        {volist name="list" id="vo"}
                        <option value="{$vo.id}" <?php if($vo["id"] == $user["user_type"]){ ?> selected <?php } ?>>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="title" class="col-md-3 control-label">
                    <div class="text-center">用户账号</div>
                </label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="username" value="{$user.username}"
                           name="username" placeholder="输入用户账号" disabled="disabled">
                </div>
            </div>
            <div class="form-group">
                <label for="title" class="col-md-3 control-label">
                    <div class="text-center">用户密码</div>
                </label>
                <div class="col-md-9">
                    <input type="password" class="form-control" id="password"
                           name="password" placeholder="输入用户密码">
                </div>
            </div>
            <div class="form-group">
                <label for="title" class="col-md-3 control-label">
                    <div class="text-center">用户邮箱</div>
                </label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="email" value="{$user.email}"
                           name="email" placeholder="输入用户邮箱">
                </div>
            </div>
            <div class="form-group">
                <label for="title" class="col-md-3 control-label">
                    <div class="text-center">用户手机号码</div>
                </label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="mobile" value="{$user.mobile}"
                           name="mobile" placeholder="输入用户手机号码">
                </div>
            </div>
            <div class="form-group save-btn">
                <button type="button" onclick="return getUser('__HTTP__')" >保存</button>
                <button type="button" onclick="javascript:history.back(-1);return false;" style="background: red;">取消</button>
            </div>
        </form>
    </div>
</row>
<script>

    //用户编辑
    function getUser(url) {
        var nickname = document.getElementById("nickname").value;
        if(nickname == ""){
            ERRORAlert("请输入您的昵称");
            return false;
        }
        var user_type = document.getElementById("user_type").value;
        if(user_type == 0){
            layer.msg("请选择用户类型",
                {icon:2,time:2000,offset:'t',closeBtn:0,shift:4});
            return false;
        }
        var password = $('input[name="password"]').val();
        if(password == ""){
            ERRORAlert("请输入您的密码");
            return false;
        }
        if(!util.validate(password,"password")){
            ERRORAlert("密码最少6-20个字母、数字、下划线");
            return false;
        }
        var email = $('input[name="email"]').val();
        if(email == ""){
            ERRORAlert("请输入您的邮箱号码");
            return false;
        }
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if(!myreg.test(email)){
            ERRORAlert("您输入的邮箱号码不合法");
            return false;
        }
        var mobile = $('input[name="mobile"]').val();
        if(mobile == ""){
            ERRORAlert("请输入您的手机号码");
            return false;
        }
        var pattern=/^((13[0-9])|(15[1-3,5-9])|(17[7])|(18[0-9]))\d{8}$/;
        if(!pattern.test(mobile)){
            ERRORAlert("您输入的手机号码不合法");
            return false;
        }
        var id = $('input[name="id"]').val();
        $.ajax({
            type:"post",
            url:url+"/UserEdit",
            data:{
                "id":id,
                "mobile":mobile,
                "email":email,
                "password":password,
                "nickname":nickname,
                "user_type":user_type
            },
            success:function (res) {
                console.log(res);
                SUCCESSAlert("用户编辑成功");
                window.setTimeout("window.location='"+url+"/User'",3000);
            }
        });
        return true;
    }
</script>